package com.alt.www.sort;

/**
 * Created by wangyang on 2017/8/3.
 */
public class SelectTion {
    public static void main(String[] args){

    }
    public static void sort(Comparable[] array){
        int length = array.length;
        for(int index=0;index<length;index++){
            Comparable min = null;
            int minIndex = 0;
            for(int findminindex = index;findminindex<length; findminindex++){
                if(min==null){
                    min = array[findminindex];
                    minIndex = findminindex;
                    continue;
                }
                if(less(min, array[findminindex])){
                    exch(array, minIndex, findminindex);
                }
            }
        }
    }

    private static boolean less(Comparable v, Comparable w){
        return  v.compareTo(w)<0;
    }

    private static void exch(Comparable[] a, int i, int j){
        Comparable temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    private static void show(Comparable[] array){
        for(Comparable a:array){
            System.out.print(a+" ");
        }
        System.out.println(" ");
    }
    public static boolean isSorted(Comparable[] array){
        for(int index=0;index<array.length;index++){
            if(less(array[index],array[index+1]))
                return false;
        }
        return true;
    }

}
